package com.example.demo.repository;

import com.example.demo.entity.OperatorEntity;
import com.example.demo.vo.OperatorVO;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Map;

/**
 *@Description 操作员仓库层
 *@Author Levi
 *@Date 2019/4/23-16:44
*/
public interface OperatorRepository extends JpaRepository<OperatorEntity, Long> {
    Integer countByUsernameEqualsAndDelSignNot(String username, Integer delSign);

    List<OperatorEntity> findAllByUsernameEqualsAndDelSignNot(String username, Integer delSign);

    @Query(value = "SELECT  " +
            " operator.id AS id, " +
            " operator.username AS username, " +
            " INET_NTOA( operator.last_login_ip ) AS lastLoginIP, " +
            " UNIX_TIMESTAMP( operator.last_login_time ) AS lastLoginTime, " +
            " operator.login_times AS loginTimes  " +
            "FROM " +
            " t_operator operator  " +
            "WHERE " +
            " operator.username LIKE CONCAT('%', ?1, '%')  " +
            " AND operator.del_sign = ?2", nativeQuery = true)
    Page<Map<String, Object>> findAll(String username, Integer delSign, Pageable pageable);
}
